﻿using System;
using System.Collections.Generic;
using System.Data;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class TotalWorkOfStaffRepository :
        BaseRepository<TotalWorkOfStaff, SmatimeDataset.TotalWorkOfStaffDataTable, TotalWorkOfStaffTableAdapter>
    {
        /// <summary>
        ///     get total work of staff by curent month and id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<TotalWorkOfStaff> GetTotalWorkBy(long id, DateTime month)
        {
            using (var adapter = new TotalWorkOfStaffTableAdapter())
            {
                using (var table = adapter.GetDataBy(id, month))
                {
                    var list = new List<TotalWorkOfStaff>();
                    foreach (DataRow row in table.Rows)
                    {
                        var totalWork = new TotalWorkOfStaff();
                        totalWork.FromDataRow(row);
                        list.Add(totalWork);
                    }
                    return list;
                }
            }
        }

        /// <summary>
        /// get total work of staff by curent month and id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<TotalWorkOfStaff> GetByStampDate(long companyId, DateTime stampdate, string storeName)
        {

            using (var adapter = new TotalWorkOfStaffTableAdapter())
            {
                using (var table = adapter.GetDataByStampdate(companyId, stampdate, storeName))
                {
                    var list = new List<TotalWorkOfStaff>();
                    foreach (DataRow row in table.Rows)
                    {
                        var totalWork = new TotalWorkOfStaff();
                        totalWork.FromDataRow(row);
                        list.Add(totalWork);
                    }
                    return list;
                }
            }
        }
    }
}